<template>
	<view>
		<view class="search-bar">
			<u-search placeholder="请输入小区或地铁站搜索" :show-action="false" :disabled="true" @click="gotoSearch" 
			:input-style="{width: '500rpx'}" />
		</view>

		<view v-for="(item,index) in hourseDataList" :key="index">
			<view v-if="item.plateName === '最多人看'">
				<mostPeopleSee :dataList="item"></mostPeopleSee>
			</view>
			<view v-if="item.plateName === '为你推荐'">
				<recommandForYou :dataList="item"></recommandForYou>
			</view>
			<view v-if="item.plateName === '最新发布'">
				<guessYourLike :dataList="item"></guessYourLike>
			</view>
		</view>
	</view>
</template>

<script>
	import mostPeopleSee from '../components/palte/mostPeopleSee.vue'
	import guessYourLike from '../components/palte/guessYourLike.vue'
	import recommandForYou from '../components/palte/recommandForYou.vue'
	export default {
		data() {
			return {
				hourseDataList: [],
				plateList: []
			};
		},
		onLoad() {
			this.getHouseDataList();
		},
		// onShow() {
		// 	this.getHouseDataList();
		// },
		methods: {
			//刷新
			onRefresh() {
				//在当前页面显示导航条加载动画
				wx.showNavigationBarLoading();
				//显示 loading 提示框。需主动调用 wx.hideLoading 才能关闭提示框
				wx.showLoading({
					title: '刷新中...',
				})
				this.getData();
			},
			//网络请求，获取数据
			getData() {
				this.getHouseDataList()
				wx.request({
					url: '',
					//网络请求执行完后将执行的动作
					complete(res) {
						//隐藏loading 提示框
						wx.hideLoading();
						//隐藏导航条加载动画
						wx.hideNavigationBarLoading();
						//停止下拉刷新
						wx.stopPullDownRefresh();
					}
				})
			},
			/**
			 * 页面相关事件处理函数--监听用户下拉动作
			 */
			onPullDownRefresh: function() {
				//调用刷新时将执行的方法
				this.onRefresh();
			},
			
			//获取房屋列表信息
			async getPlateList() {
				let res = await this.$request({
					url: '/v1/plate/list',
				})
				// console.log(res)
				if (!res.isSuccess) {
					// console.log(res.message)
				}
				this.plateList = res.data

			},
			async getHouseDataList() {
				this.hourseDataList = []
				await this.getPlateList()
				// console.log(this.plateList)
				var recommandId = ''
				for (let i = 0; i < this.plateList.length; i++) {
					if (this.plateList[i].name === '最新发布') {
						recommandId = this.plateList[i].id
					}
				}
				// console.log(recommandId)
				for (let i = 0; i < this.plateList.length; i++) {
					let houseItem = {}
					let houseData = await this.$request({
						url: '/v1/house/list?plateId=' + this.plateList[i].id + '&type=0' + '&isApproved=1'
					})
					houseItem = {
						"recommandId": recommandId,
						"plateName": this.plateList[i].name,
						"houseInfo": houseData.data,
						"isShowPlateName": true
					}
					this.hourseDataList.push(houseItem)
				}
				// console.log(this.hourseDataList)
			},
			gotoSearch(){
				// console.log("点了")
				wx.navigateTo({
					url: '../components/search'
				})
			}
		},
		
		components: {
			mostPeopleSee,
			guessYourLike,
			recommandForYou
		}
	}
</script>

<style lang="scss">
	page{
		width: auto;
		padding-left: 20rpx;
		padding-right: 20rpx;
	}
	.search-bar {
		height: 70rpx;
		margin-top: 20rpx;
	}

	.bar {
		height: 96rpx;
	}

	.rent-two-box {
		margin-top: 20rpx;
		margin-left: 30rpx;
		height: 240rpx;
	}

	.rent-one-box {
		margin-top: 20rpx;
		height: 400rpx;
		margin-bottom: 20rpx;
	}


	.img-list-box {
		height: 160rpx;
	}

	.img-list {
		height: 160rpx;
		width: 240rpx;
	}
</style>
